package cn.cqsw.dao;

import java.sql.*;

public class BaseDao {
    //四个常量
    public static final String DRIVER_NAME="com.mysql.jdbc.Driver";
    public static final String URL="jdbc:mysql:///jsp_test01";
    public static final String USER="root";
    public static final String PWD="root";
    //加载驱动类
    static {
        try {
            Class.forName(DRIVER_NAME);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    //获取连接
    public static Connection getConn() throws SQLException {
        return DriverManager.getConnection(URL,USER,PWD);
    }
    //释放资源
    public static void close(ResultSet rs, PreparedStatement ps,Connection conn) throws SQLException {
        if(rs!=null){
            rs.close();
        }
        if(ps!=null){
            ps.close();
        }
        if(conn!=null){
            conn.close();
        }
    }

}
